package com.leetcode;

/**
 * 806. 写字符串需要的行数
 *
 * @author fy
 * @date 2022/4/12 16:16
 */
public class Solution806 {

    public int[] numberOfLines(int[] widths, String s) {
        if (s == null || s.length() == 0) {
            return new int[]{0, 0};
        }
        int lineWidth = 100;
        int line = 1;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            int charWidth = widths[ch - 'a'];
            lineWidth -= charWidth;
            if (lineWidth < 0) {
                lineWidth = 100 - charWidth;
                line++;
            }
        }
        return new int[]{line, 100 - lineWidth};
    }

}
